package ptij.vocoder.baseModel.closed_loop;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.Token;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// ComputeCond
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class ComputeCond extends TypedAtomicActor {

    public ComputeCond(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        txdtx_ctrl = new TypedIOPort(this, "txdtx_ctrl", true, false);
        txdtx_ctrl.setTypeEquals(BaseType.OBJECT);

        cond1 = new TypedIOPort(this, "cond1", false, true);
        
        cond2 = new TypedIOPort(this, "cond2", false, true);
        
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort txdtx_ctrl;

    // Output Ports
    public TypedIOPort cond1;
    public TypedIOPort cond2;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) txdtx_ctrl.get(0);
        Short s = (Short) obj.getValue();
        
        if((s.shortValue() & Cnst.TX_SP_FLAG) == 0) {
            cond1.broadcast(new Token());
        }
        else {
            cond2.broadcast(new Token());
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////


    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

}
